#ifndef __BLOCK_MANAGER_H__
#define __BLOCK_MANAGER_H__

#include "cocos2d.h"

#include "object/Block.h"
#include <vector>
#include "my_def.h"

using namespace cocos2d;

class CBlock_Manager : public CCLayer
{
public:
	CBlock_Manager();
	~CBlock_Manager();

	LAYER_NODE_FUNC(CBlock_Manager);

	virtual void onEnter();
	virtual void onExit();
	//bool containsTouchLocation(CCTouch* touch);
	virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event);
	virtual void ccTouchMoved(CCTouch* touch, CCEvent* event);
	virtual void ccTouchEnded(CCTouch* touch, CCEvent* event);
	virtual void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent);

	/*virtual void ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent);
	virtual void ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent);
	virtual void ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent);
	virtual void ccTouchesCancelled(CCSet *pTouches, CCEvent *pEvent);*/

private:
	bool init();

	int GenerateValidType();
	void CreateBolck();

	int FindBlock(CCPoint pt);
	bool GetGridPostion(int nIdx, CCPoint& retPt );
	bool CalibrationPosition(CCPoint pt, CCPoint& retPt);

private:
	
	std::map<int,int> m_vSelectedBlock;

	int m_nBlockTypeCount[E_BLOCK_MAX];

	std::vector<CBlock*> m_vBlocks;

	bool m_bMovedBlock;

	CCPoint m_toucheBeginPt;
};

#endif //__BLOCK_MANAGER_H__